<?php
namespace app\index\controller;
use app\index\model\Channel;
// use app\index\
class Page extends Base
{
    public function index()
    {   
        $id=request()->param('id');
        $viewPage=$this->getIndexPage($id);  
        $p=request()->param('p'); 
        if(!$p){
            $p=1;
        }

        $channelModel=new Channel();
        if($id){
            $mark=$channelModel->getMarkByid($id);
        }else{
            $mark="index";
        }
        $pid=$channelModel->getFieldById($id,"pid");
        if($pid > 0){
            $gcid=$pid;
            $pcid=$id;
            $where['cid']=$id;
            $lchannel=$channelModel->getLeftChannel($pid);
            $fname=$channelModel->getFieldById($pid,"name");
        }else{
            $gcid=$id;
            $pcid=$channelModel->getIdByPid($id);
            // $pcid=$channel->where("status=1 and pid=".$id)->order("sort asc ,id desc")->value("id");;
            $where['cid']=$pcid;
            $lchannel=$channelModel->getLeftChannel($id);
            $fname=$channelModel->getFieldById($id,"name");
        }
        // $mess=$this->getData($mark,$where,$p);
        // $id=request()->param('id');       
        $article=db("cms_article");
        $channel=db("channel");
                
        // $pid=$channel->where("id=".$id)->value("pid");
        // if($pid > 0){
        //     $gcid=$pid;
        //     $pcid=$id;
        //     $where['cid']=$id;
        //     $lchannel=$this->get_left_channel($pid);
        //     $fname=$channel->where("id",$pid)->value("name");
        // }else{
        //     $gcid=$id;
        //     $pcid=$channel->where("status=1 and pid=".$id)->order("sort asc ,id desc")->value("id");;
        //     $where['cid']=$pcid;
        //     $lchannel=$this->get_left_channel($id);
        //     $fname=$channel->where("id",$id)->value("name");
        // }
        $where['status']=1;
        
        $mess=$article->where($where)->find();

        $gnavName=$channel->where("id=".$gcid)->value("name");

        $pnavName=$channel->where("id=".$pcid)->value("name");

        // SEO META关键字配置
        $meta=$this->meta;
        $meta['title']=$mess['title'].' '.$pnavName.' '.$gnavName.' '.$meta['title'];
        if($mess['keywords']){
            $meta['keywords']=$mess['keywords'];
        }else{
            $meta['keywords']=$mess['title'].$pnavName.$gnavName.$meta['keywords'];
        }
        if($mess['descript']){
            $meta['descript']=$mess['descript'];
        }else{
            $meta['descript']=$mess['title'].$pnavName.$gnavName.$meta['descript'];
        }
        $this->assign("meta",$meta);

        
        $banner=$this->get_banner($gcid);
        
        $modelx=$channel->where("id",$gcid)->value("modelx");
        $modelxMark=db("modelx")->where("id=".$modelx)->value("mark");
        $this->assign("modelxMark",$modelxMark);
        
        $this->assign("banner",$banner);
        $this->assign("pnavName",$pnavName);
        $this->assign("gnavName",$gnavName);
        $this->assign("lchannel",$lchannel);
        $this->assign("cid",$cid);
        $this->assign("gcid",$gcid);
        $this->assign("pcid",$pcid);
        $this->assign("fname",$fname);
        $this->assign("mess",$mess);
		return view($viewPage);
    }
}
